Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
prosemirror-transform
Advanced tools
The prosemirror-transform package is a part of the ProseMirror toolkit, which provides a set of tools for building rich-text editors. This package specifically deals with transforming ProseMirror documents, allowing you to apply changes, manipulate document structure, and handle collaborative editing scenarios.
Applying Steps
This feature allows you to apply a step to a ProseMirror document. Steps are atomic changes that can be applied to a document, such as inserting or deleting content.
const { Step } = require('prosemirror-transform');
const { Schema, DOMParser } = require('prosemirror-model');
const { schema } = require('prosemirror-schema-basic');
let doc = DOMParser.fromSchema(schema).parse(document.querySelector('#content'));
let step = new Step();
let result = step.apply(doc);
console.log(result.doc);
Transformations
This feature allows you to create a transformation and apply multiple changes to a document. Transformations can include inserting, deleting, or replacing content.
const { Transform } = require('prosemirror-transform');
const { Schema, DOMParser } = require('prosemirror-model');
const { schema } = require('prosemirror-schema-basic');
let doc = DOMParser.fromSchema(schema).parse(document.querySelector('#content'));
let tr = new Transform(doc);
tr.insert(1, schema.text('Hello, world!'));
console.log(tr.doc);
Mapping Positions
This feature allows you to map positions in a document, which is useful for collaborative editing where multiple users are making changes simultaneously. The Mapping class helps keep track of position changes.
const { Mapping } = require('prosemirror-transform');
let mapping = new Mapping();
mapping.appendMap({ map: [0, 1, 2, 3] });
let newPos = mapping.map(2);
console.log(newPos);
Slate is a completely customizable framework for building rich text editors. It provides a set of tools for transforming documents, similar to prosemirror-transform, but with a different API and more focus on React integration.
Draft.js is a framework for building rich text editors in React. It offers similar document transformation capabilities but is more tightly integrated with React and provides a different set of abstractions for handling content.
Quill is a powerful, rich text editor that provides a simple API for transforming documents. It is less modular than ProseMirror but offers a more out-of-the-box solution for common rich text editing needs.
[ WEBSITE | ISSUES | FORUM | GITTER | CHANGELOG ]
ProseMirror is a well-behaved rich semantic content editor based on contentEditable, with support for collaborative editing and custom document schemas.
This module implements document transforms, which are used by the editor to treat changes as first-class values, which can be saved, shared, and reasoned about.
The project page has more information, a number of examples and the documentation.
This code is released under an MIT license. There's a forum for general discussion and support requests, and the Github bug tracker is the place to report issues.
0.23.0 (2017-09-13)
Step.toJSON
no longer has a default implementation.
Steps no longer have an offset
method. Map them through a map created with StepMap.offset
instead.
The clearMarkup
method on Transform
is no longer supported (you probably needed clearIncompatible
anyway).
Pasting a list item at the start of a non-empty textblock now wraps the textblock in a list.
Marks on open nodes at the left of a slice are no longer dropped by Transform.replace
.
StepMap
now has a static method offset
, which can be used to create a map that offsets all positions by a given distance.
Transform objects now have a clearIncompatible
method that can help make sure a node's content matches another node type.
FAQs
ProseMirror document transformations
The npm package prosemirror-transform receives a total of 1,418,676 weekly downloads. As such, prosemirror-transform popularity was classified as popular.
We found that prosemirror-transform demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.